package com.wugui.datatx.core.biz.client;

import java.util.List;

import com.wugui.datatx.core.biz.AdminBiz;
import com.wugui.datatx.core.biz.model.HandleCallbackParam;
import com.wugui.datatx.core.biz.model.HandleProcessCallbackParam;
import com.wugui.datatx.core.biz.model.RegistryParam;
import com.wugui.datatx.core.biz.model.ReturnT;
import com.wugui.datatx.core.util.JobRemotingUtil;

import lombok.extern.slf4j.Slf4j;

/**
 * admin api test
 *
 * @author xuxueli 2017-07-28 22:14:52
 */
@Slf4j
public class AdminBizClient implements AdminBiz {

    public static int timeout = 5;

	public AdminBizClient() {
	}

	public AdminBizClient(String addressUrl, String accessToken) {
		this.addressUrl = addressUrl;
		this.accessToken = accessToken;

		// valid
		if (!this.addressUrl.endsWith("/")) {
			this.addressUrl = this.addressUrl + "/";
		}
	}

	private String addressUrl;
	private String accessToken;

	@Override
	public ReturnT<String> callback(List<HandleCallbackParam> callbackParamList) {
        return JobRemotingUtil.postBody(addressUrl + "api/callback", accessToken, callbackParamList, timeout);
	}

	@Override
	public ReturnT<String> processCallback(List<HandleProcessCallbackParam> callbackParamList) {
        return JobRemotingUtil.postBody(addressUrl + "api/processCallback", accessToken, callbackParamList, timeout);
	}

	@Override
	public ReturnT<String> registry(RegistryParam registryParam) {
		log.debug(">>>>>>>>>>> datax-web, executor registry trying: {}", addressUrl + "api/registry");
        return JobRemotingUtil.postBody(addressUrl + "api/registry", accessToken, registryParam, timeout);
	}

	@Override
	public ReturnT<String> registryRemove(RegistryParam registryParam) {
        return JobRemotingUtil.postBody(addressUrl + "api/registryRemove", accessToken, registryParam, timeout);
	}
}
